package com.vcaresolution.logistic.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.vcaresolution.logistic.pojo.Department;

/**
 * The <code>BranchDAO</code> class is a DAO Associated to do various 
 * options at DAO level for Branch
 *
 * @author Sneahl Shah
 * @version 1.0
 * @since ShipSoft 1.0
 */
@Repository
public class BranchDAO extends BaseDAO{

	@SuppressWarnings("unchecked")
	@Transactional
	public List<Department> getAssociatedDepartmentList(Serializable branchId){
		
		/**#editedByVishal*/
		Integer branchIdInteger = null;
		if(branchId instanceof String)
		{
			branchIdInteger = Integer.parseInt((String) branchId);
		}
		else
		{
			branchIdInteger = (Integer)branchId;
		}
		
		List<Department> departmentList = sessionFactory
										.getCurrentSession()
										.createCriteria(Department.class,"department")
										.createAlias("department.branch", "branch")
										.setFetchMode("branch", FetchMode.JOIN)
										.add(Restrictions.eq("branch.branchid", branchIdInteger))
										.list();
		
		return departmentList;
	}
	
	/**#editedByVishal*/
	@SuppressWarnings("unchecked")
	@Transactional
	public List<Department> getAssociatedDepartmentList(Set<Integer> branchIdSet){
		
		List<Department> departmentList = sessionFactory
										.getCurrentSession()
										.createCriteria(Department.class,"department")
										.createAlias("department.branch", "branch")
										.setFetchMode("branch", FetchMode.JOIN)
										.add(Restrictions.in("branch.branchid", branchIdSet))
										.list();
		
		return departmentList;
	}
	
}
